module.exports = {
  type: 'list',

  async fetch({ args }) {
    let items = []
    let url = `http://baobab.kaiyanapp.com:80/api/v2/video/` + this.args.id
    let resp = await $http.get(url)
    let list = resp.data.playInfo
    let action = [
      {
        title: '立即观看',
        route: $route('@video', {
          url: resp.data.playUrl
        })
      }
    ]

    for (i = 0; i < list.length; i++) {
      let name = list[i].name
      let url = list[i].url
      tag(name, url)
    }
    
    
    items.push({
      style: 'richMedia',
      thumb: resp.data.cover.feed,
      title: resp.data.title,
      summary: resp.data.description,
      subtitle: getLocalTime(resp.data.date),
      actions: action
    })

    function tag(name, url) {
      action.push({
        title: name,
        route: $route('@video', {
          url: url
        })
      })
    }

    function getLocalTime(nS) {
      return new Date(parseInt(nS)).toLocaleString().replace(/:\d{1,2}$/, ' ')
    }

    return {
      items: items
    }
  }
}
